<template>
	<view class="comment-container" :style="{ bottom: bottom + 'px' }">
		<uni-easyinput v-model="value" placeholder="说点什么..." type="textarea"
			maxlength='50' :inputBorder='false'>
		</uni-easyinput>
		<button size="mini" type="primary" :disabled="!value" @click="onBtnClick">发送</button>
	</view>
</template>

<script>
	import { userArticleComment } from '../../api/user.js'
	export default {
		name: "article-comment-commit",
		props: {
			articleId: {
				type: String,
				required: true
			}
		},
		data() {
			return {
				value: '',
				bottom: 0
			}
		},
		methods: {
			async onBtnClick() {
				uni.showLoading({
					title: '加载中'
				})
				const { data: res } = await userArticleComment({
					articleId: this.articleId,
					content: this.value
				})
				uni.showToast({
					title: '发表成功',
					icon: 'success',
					mask: true
				})
				this.$emit('success', res)
			}
		},
		created() {
			// 检测软键盘的变化 动态定位
			uni.onKeyboardHeightChange(({ height }) => {
				this.bottom = height
				console.log(this.bottom)
			})
		}
	}
</script>

<style lang="scss" scoped>
	.comment-container {
		background-color: $uni-bg-color;
		text-align: right;
		padding: $uni-spacing-row-base;
		position: relative;
	}
</style>
